$(function(){

    var str = location.search;
    var id = +str.slice(1).split("=")[1];
    var id2 = null;

    $.ajax({
        url: "http://127.0.0.1:9090/api/getbrand",
        data: { brandtitleid: id},
        dataType: "json",
        success: function(result){
            console.log(result);
            $(".complete-title").html(template("temp-title", result));
            $(".complete-title").children("li")[0].classList.add("red");
            $(".complete-title").children("li")[1].classList.add("origin");
            $(".complete-title").children("li")[2].classList.add("green");
        }
    });

    $.ajax({
        url: "http://127.0.0.1:9090/api/getbrandproductlist",
        data: { brandtitleid: id},
        dataType: "json",
        success: function(result){
            console.log(result);
            // console.log(result.result[0].productId);
            $(".mm-product").html(template("temp-product",result));
            id2 = $(".mm-product").children(".item").data("id");
            render(id2);
        }
    });

    function render(id2){
        $.ajax({
            url: "http://127.0.0.1:9090/api/getproductcom",
            data: { productid: id2 },
            dataType: "json",
            success: function (result) {
                console.log(result);
                $(".comment").html(template("temp-comment",result));
            }
        });
    }
    render();

});